package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.dto.NursingProjectPageDTO;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/nursing_project")
@Api(tags = "护理项目相关接口")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("分页查询")
    public ResponseResult page(NursingProjectPageDTO nursingProjectPageDTO){
        PageResponse pageResponse = nursingProjectService.pageCondition(nursingProjectPageDTO);
        return success(pageResponse);
    }

    @PostMapping
    @ApiOperation("新增护理项接口")
    public ResponseResult insert(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.insert(nursingProjectDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据Id查询护理项接口")
    public ResponseResult getById(@PathVariable Long id){
       NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return  success(nursingProjectVo);
    }
    @PutMapping
    @ApiOperation("修改护理项就接口")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto ){
        nursingProjectService.update(nursingProjectDto);
        return  success();
    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("更改护理项状态")
    public ResponseResult updateStatus(@PathVariable Long id,@PathVariable Integer status){
        NursingProjectDto nursingProjectDto = new NursingProjectDto();
        nursingProjectDto.setId(id);
        if (status==0){status=1;
        }else if (status==1){
            status=0;
        }
        nursingProjectDto.setStatus(status);
        nursingProjectService.update(nursingProjectDto);
        return success();
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项")
    public ResponseResult delete(@PathVariable Long id){
        NursingProjectDto nursingProjectDto = new NursingProjectDto();
        nursingProjectDto.setId(id);
        nursingProjectDto.setIsDelete(1);
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    @GetMapping("/all")
    @ApiOperation("查询所有护理项")
    public ResponseResult selectAll(){
      List<NursingProjectVo> voList = nursingProjectService.selectAll();
      return success(voList);
    }

}
